﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.IO;
using LevenBlog.Core.Data;
using LevenBlog.Core.Entities;

namespace LevenBlog.Core.Service
{
    public static class File
    {
        public static int Count(IDbProvider provider)
        {
            return ProviderManager.Factory.File.Count(provider);
        }

        public static lb_file Get(IDbProvider provider, int id)
        {
            return ProviderManager.Factory.File.Get(provider, id);
        }

        public static IList<lb_file> Get(IDbProvider provider, int pageSize, int currentPage)
        {
            return ProviderManager.Factory.File.Get(provider, pageSize, currentPage);
        }

        public static void Insert(IDbProvider provider, lb_file file)
        {
            ProviderManager.Factory.File.Insert(provider, file);
        }

        public static lb_file InsertAndGet(IDbProvider provider, lb_file file)
        {
            provider.BeginTransaction();
            try
            {
                ProviderManager.Factory.File.Insert(provider, file);
                file = ProviderManager.Factory.File.Get(provider, 1, 1)[0];
                provider.Commit();
                return file;
            }
            catch
            {
                provider.Rollback();
                throw;
            }
        }

        public static void Update(IDbProvider provider, lb_file file)
        {
            ProviderManager.Factory.File.Update(provider, file);
        }

        public static void Delete(IDbProvider provider, int id)
        {
            ProviderManager.Factory.File.Delete(provider, id);
        }
    }
}
